﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_City_ManageArea : System.Web.UI.Page
{
    public int CityID
    {
        get { return Convert.ToInt32(ViewState["_CityID"]); }
        set { ViewState["_CityID"] = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CityID = DongDong.Common.Misc.GetQueryStringAsInt("CityID");
            //City objCity = City.Get(CityID);
            //if (objCity != null)
            //{
            //    labShi.Text = objCity.Name ?? "暂无信息";
            //}

        }
    }

    public void PopulateQuyuList()
    {
        //lv_QuYuList.DataSource = Area.GetAllByCity(CityID);
        //lv_QuYuList.DataBind();
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (CityID != 0)
        {
            //Area objArea = new Area();
            //objArea.CityID = CityID;
            //objArea.Name = txtQuYu.Text.Trim();
            //objArea.Add();
            //litMessage.Text = "添加成功！";
        }
        else
        {
            litMessage.Text = "未选择城市，请选择！";
        }
    }
    protected void lv_QuYuList_ItemCanceling(object sender, ListViewCancelEventArgs e)
    {
        lv_QuYuList.EditIndex = -1;
        PopulateQuyuList();
    }
    protected void lv_QuYuList_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        //Area.Delete(DongDong.Common.Misc.ConvertToInt(lv_QuYuList.DataKeys[e.ItemIndex].Value));
        PopulateQuyuList();
    }
    protected void lv_QuYuList_ItemUpdating(object sender, ListViewUpdateEventArgs e)
    {
        int AreaID = DongDong.Common.Misc.ConvertToInt(lv_QuYuList.DataKeys[e.ItemIndex].Value);
        //Area objType = Area.Get(AreaID);
        //var item = lv_QuYuList.Items[e.ItemIndex];
        //TextBox txtEditTitle = (TextBox)item.FindControl("txtEditTitle");
        //objType.Name = txtEditTitle.Text;

        //objType.Update();
        lv_QuYuList.EditIndex = -1;
        PopulateQuyuList();
    }
    protected void lv_QuYuList_ItemEditing(object sender, ListViewEditEventArgs e)
    {
        lv_QuYuList.EditIndex = e.NewEditIndex;
        PopulateQuyuList();
    }
    protected void lv_QuYuList_PagePropertiesChanged(object sender, EventArgs e)
    {
        PopulateQuyuList();
    }
    protected void Pager_PreRender(object sender, EventArgs e)
    {
        if (lv_QuYuList.Items.Count == 0)
            PopulateQuyuList();
    }

    public string ReturnCityName(object cityID)
    {
        string cityName = "暂无信息";
        //City objCity = City.Get(DongDong.Common.Misc.ConvertToInt(cityID));
        //if (objCity != null)
        //{
        //    cityName = objCity.Name;
        //}
        return cityName;
    }
}